package com.park.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.park.dao.UserlistMapper;
import com.park.dao.UserlistPermissionsMapper;
import com.park.model.Permissions;
import com.park.model.UserList;
import com.park.model.UserlistPermissions;
import com.park.service.UserListService;

@Service
public class UserListServiceImpl implements UserListService {

	@Autowired
	private UserlistMapper userListMapper;
	@Autowired
	private UserlistPermissionsMapper userlistPermissionsMapper;
	@Override
	public UserList getByUserName(String userListname) {
		// TODO Auto-generated method stub
		return userListMapper.getByUserName(userListname);
	}

	@Override
	public int insert(UserList userList) {
		// TODO Auto-generated method stub
		return userListMapper.insertSelective(userList);
	}

	@Override
	public int bindingRoles(List<UserlistPermissions> userlistPermissions) {
		// TODO Auto-generated method stub
		return userlistPermissionsMapper.insert(userlistPermissions);
	}

	@Override
	public int updateRoles(UserlistPermissions userlistPermissions) {
		// TODO Auto-generated method stub
		return userlistPermissionsMapper.update(userlistPermissions);
	}

	@Override
	public int deleteRoles(List<UserlistPermissions> userlistPermissions) {
		// TODO Auto-generated method stub
		return userlistPermissionsMapper.deleteRoles(userlistPermissions);
	}

	@Override
	public List<Long> getByUserId(Long id) {
		// TODO Auto-generated method stub
		return userListMapper.getByUserId(id);
	}

	@Override
	public List<UserList> getUserByName(String userName) {
		// TODO Auto-generated method stub
		return userListMapper.getUserByName(userName);
	}

	@Override
	public List<UserList> getUser(List<Long> ids) {
		// TODO Auto-generated method stub
		return userListMapper.getUser(ids);
	}

	@Override
	public UserList recursiveTree(Long long1) {
		UserList node = userListMapper.getreeNode(long1);
		List<UserList> childTreeNodes = userListMapper.queryTreeNode(long1); 
		for(UserList child : childTreeNodes){
			UserList n = recursiveTree(child.getId()); //递归
		node.getChildren().add(n);
		}
		return node;
	}

	@Override
	public int deleteByUserId(Long userlistId) {
		// TODO Auto-generated method stub
		return userlistPermissionsMapper.deleteByUserId(userlistId);
	}

	@Override
	public List<Permissions> getRoleByUserId(int userId) {
		// TODO Auto-generated method stub
		return userlistPermissionsMapper.getRoleByUserId(userId);
	}

	@Override
	public int updateUser(UserList userList) {
		// TODO Auto-generated method stub
		return userListMapper.updateByPrimaryKey(userList);
	}

	@Override
	public int deleteById(List<Long> ids) {
		// TODO Auto-generated method stub
		return userListMapper.deleteById(ids);
	}
}
